import { defineStore } from 'pinia';
import {ref} from "vue";

export const useAuthStore = defineStore('authinfo',()=>{
    const token = ref(localStorage.getItem('ct_token'))
    const unit_id = ref(localStorage.getItem('ct_unit_id'))
    function setToken(newToken) {
        token.value = newToken
        if (newToken) {
            localStorage.setItem('aiops_token', newToken)
        } else {
            localStorage.removeItem('aiops_token')
        }
    }
    function setUnitId(newUnitId) {
        unit_id.value = newUnitId
        if (newUnitId) {
            localStorage.setItem('aiops_unit_id', newUnitId)
        } else {
            localStorage.removeItem('aiops_unit_id')
        }
    }
    function logout() {
        setToken(null);
        setUnitId(null);
    }
    return {token, unit_id, setToken, setUnitId, logout}
});